package md.lanjing.com.module_mine.ui.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.lxh.baselibray.mvp.MvpActivity;
import com.lxh.baselibray.util.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import com.lxh.baselibray.constant.Constant;

import md.lanjing.com.module_mine.R;
import md.lanjing.com.module_mine.R2;
import md.lanjing.com.module_mine.bean.InviteFriendResponce;
import md.lanjing.com.module_mine.contact.InviteFriendContact;
import md.lanjing.com.module_mine.ui.adapter.InviteFriendAdapter;
import retrofit2.Response;

public class InviteFriendActivity extends MvpActivity<InviteFriendContact.InviteFriendPresent> implements InviteFriendContact.IInviteFriendView {
    public static final String LEVEL  ="level";
    @BindView(R2.id.rv)
    RecyclerView rv;

    List<InviteFriendResponce.DataBean> mList;
    InviteFriendAdapter mAdapter;
    @Override
    public void initData(Bundle savedInstanceState) {
        mList=new ArrayList<>();
        mAdapter=new InviteFriendAdapter(R.layout.recy_item_invite_friend,mList);
        LinearLayoutManager manager=new LinearLayoutManager(context);
        rv.setLayoutManager(manager);
        rv.setAdapter(mAdapter);

        int level=getIntent().getIntExtra(LEVEL,0);
        mPresent.queryDownLineFriend(context,level);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_invite_friend;
    }

    @Override
    public void getDownDetailData(Response<InviteFriendResponce> response) {
        if (response.body().getCode()== Constant.SUCCESS_CODE){
            List<InviteFriendResponce.DataBean> data = response.body().getData();
            mList.addAll(data);
            mAdapter.notifyDataSetChanged();
        }else {
            ToastUtils.showLongToast(context,response.body().getMsg());
        }
    }

    @Override
    protected InviteFriendContact.InviteFriendPresent createPresent() {
        return new InviteFriendContact.InviteFriendPresent();
    }
}
